#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>

int main(int argc, char **argv)
{
    int fd;
    int ret;
    char buff[128];

    if(mkfifo("./fifo",0640) == -1 )
    {
        if(errno != EEXIST)
        {
            perror("mkfifo");
            exit(1);
        }
    }

    fd = open("./fifo",O_RDONLY);
    if(fd == -1)
    {
        perror("open");
        exit(1);
    }
    //write data
    while(1)
    {
        memset(buff,0,sizeof(buff));
        ret = read(fd,buff,sizeof(buff) - 1);
        printf("read fifo %d %s\n",ret,buff);
        sleep(1);
    }
    return 0;
}
